﻿/*****************************************************************************
 
 Use of Ext is under the Ext JS license, for more information, 
 please visit http://extjs.com/products/license.php page. 
  
 You should confirm that you have read, understood and accept ethical criteria listed. 
 If not, see <http://www.mvcnext.com/license/>.
  
 Version: 1.0.0.0
 Website: http://www.mvcnext.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Web.UI;

namespace MVCnExt.Web.UI.Ext
{
    /// <summary>
    /// Single checkbox field. Can be used as a direct replacement for traditional checkbox fields. 
    /// </summary>
    [Description("Single checkbox field. Can be used as a direct replacement for traditional checkbox fields. ")]
    public abstract class CheckBox : Field  
    {
        public override List<ScriptReference> GetScriptReferences()
        {
            return base.GetScriptReferences();
        }

        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.form.CheckBox";

            String[] properties = new String[]{
                "autoLoad", "modal"           
            };

            Type component = typeof(ExtFormPanel);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);

                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'ExtJsPanel.{0}'", property));

                Object value = i.GetValue(this, null);

                if (value == null)
                {
                    continue;
                }

                if (!(value is String))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }                        

            return list;
        }

        #region Public Properties

        /// <summary>
        /// The text that appears beside the checkbox (defaults to '').
        /// </summary>
        [Description("The text that appears beside the checkbox (defaults to '').")]
        public String boxLabel { get; set; }

        /// <summary>
        /// True if the the checkbox should render already checked (defaults to false).
        /// </summary>
        [Description("True if the the checkbox should render already checked (defaults to false).")]
        public Boolean Checked { get; set; }

        /// <summary>
        /// The CSS class to use when the control is checked (defaults to 'x-form-check-checked'). Note that this class applies to both checkboxes and radio buttons and is added to the control's wrapper element.
        /// </summary>
        [DefaultValue("x-form-check-checked")]
        [Description("The CSS class to use when the control is checked (defaults to 'x-form-check-checked'). Note that this class applies to both checkboxes and radio buttons and is added to the control's wrapper element.")]
        public String checkedCls { get; set; }

        /// <summary>
        /// The CSS class to use when the control receives input focus (defaults to 'x-form-check-focus'). Note that this class applies to both checkboxes and radio buttons and is added to the control's wrapper element.
        /// </summary>
        [DefaultValue("x-form-check-focus")]
        [Description("The CSS class to use when the control receives input focus (defaults to 'x-form-check-focus'). Note that this class applies to both checkboxes and radio buttons and is added to the control's wrapper element.")]
        public String focusCls { get; set; }

        /// <summary>
        /// The value that should go into the generated input element's value attribute (defaults to undefined, with no value attribute)
        /// </summary>
        [Description("The value that should go into the generated input element's value attribute (defaults to undefined, with no value attribute)")]
        public String inputValue { get; set; }

        /// <summary>
        /// The CSS class to use when the control is being actively clicked (defaults to 'x-form-check-down'). Note that this class applies to both checkboxes and radio buttons and is added to the control's wrapper element.
        /// </summary>
        [DefaultValue("x-form-check-down")]
        [Description("The CSS class to use when the control is being actively clicked (defaults to 'x-form-check-down'). Note that this class applies to both checkboxes and radio buttons and is added to the control's wrapper element.")]
        public String mouseDownCls { get; set; }

        /// <summary>
        /// An optional extra CSS class that will be added to this component's Element when the mouse moves over the Element, and removed when the mouse moves out. (defaults to ''). This can be useful for adding customized 'active' or 'hover' styles to the component or any of its children using standard CSS rules.
        /// </summary>
        [DefaultValue("x-form-check-over")]
        [Description("The CSS class to use when the control is hovered over (defaults to 'x-form-check-over'). Note that this class applies to both checkboxes and radio buttons and is added to the control's wrapper element.")]
        public String overCls { get; set; }
       
        #endregion
    }
}
